package com.traffic.fuwu.controller;


import com.traffic.fuwu.mybatis.pojo.*;
import com.traffic.fuwu.service.*;
import com.traffic.fuwu.util.*;
import com.traffic.fuwu.vo.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.*;

/**
 * Created by Churcy on 2017/1/5. 用于主页面模块直接跳转
 */
@Controller
public class IndexController {
	private static final VoStatus voStatus = new VoStatus();

	@Autowired
	AccountService accountService;
	@Autowired
	AppVersionService appVersionService;
	@Autowired
	CarryService carryservice;
	@Autowired
	DeviceService deviceService;
	@Autowired
	LastHeartService lastHeartService;
	@Autowired
	EmployeeService employeeService;
	@Autowired
	LineService lineService;
	@Autowired
	CompanyService companyService;
	@Autowired
	WhiteListService whiteListService;
	@Autowired
	VehAppCarryService vehAppCarryService;
	@Autowired
	VehAppDeviceService vehAppDeviceService;
	@Autowired
	VehAppOldDeviceService vehAppOldDeviceService;
	@Autowired
	private SftpService sftpService;
	
	@RequestMapping(value = "/com/traffic/fuwu/test", method = RequestMethod.GET)
	public String test(){
		
		return "/company/com.traffic.fuwu.test";
	}
	/**
	 * 管理后台首页
	 * 
	 * @return
	 */
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public String index() {

		return "index";
	}

	/**
	 * 心跳查询页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "/traffic/selectHeart")
	public ModelAndView selectHeartIndex(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/company/heartbeat");
		Map<String, Object> map = new HashMap<>();
		String appKey = request.getParameter("appKey");
		String pageIndex = request.getParameter("pageIndex");
		if (appKey != null && appKey != "") {

			String pageSize = "10";// 每页显示的行数
			if (StringUtils.isEmpty(pageIndex)) {
				pageIndex = "1";
			}
			Page page = new Page();
			page.setPageIndex(Integer.parseInt(pageIndex));
			page.setPageSize(Integer.parseInt(pageSize));
			int count = lastHeartService.countHeart(null, null, null, appKey, null);// 查询数量
			page = ToolUtil.getPage(count, page);

			try {

				List<Map> list = lastHeartService.selectHeartFyz(null, null, null, appKey, null, page.startRow(),
						page.getPageSize());
				if (list != null && list.size() != 0) {

					List<VoLastHeart> listHeart = new ArrayList<>();

					for (int i = 0; i < list.size(); i++) {
						VoLastHeart voLastHeart = new VoLastHeart();
						String carryCode = (String) list.get(i).get("veh_no");
						String deviceId1 = (String) list.get(i).get("device_id");
						Date createTime1 = (Date) list.get(i).get("create_time");
						int locate1 = (int) list.get(i).get("locate");
						if (locate1 == 0) {
							String locate2 = "正常";
							voLastHeart.setLocate(locate2);
						} else {
							String locate2 = "出错";
							voLastHeart.setLocate(locate2);
						}
						voLastHeart.setCarryCode(carryCode);
						voLastHeart.setDeviceId(deviceId1);
						voLastHeart.setCreateTime(createTime1);
						listHeart.add(voLastHeart);
					}
					/*
					 * String[] head = new String[] { "车牌号", "机具编号", "最新上传数据时间",
					 * "实时状态" };
					 */
					VoLastHeart head = new VoLastHeart();
					head.setCarryCode("车牌号");
					head.setDeviceId("机具编号");
					head.setLocate("实时状态");
					map.put("head", head);
					map.put("line", listHeart);
					map.put("page", page);
					voStatus.setCode(1);
					voStatus.setMessage("查询成功");
					map.put("status", voStatus);
				} else {
					map.put("head", "没有查询到相关数据");
					voStatus.setCode(0);
					voStatus.setMessage("没有查到相关数据");
					map.put("status", voStatus);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		map.put("head", "无效appKey");
		mv.addObject("result", map);
		return mv;
	}

	/**
	 * 设备管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "/traffic/equipment")
	public ModelAndView equipmentIndex(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/company/equipment");
		String response = null;
		String pageIndex = request.getParameter("pageIndex");
		String appKey = request.getParameter("appKey");
		Map<String, Object> map = new HashMap<>();

		String pageSize = "10";
		if (StringUtils.isEmpty(pageIndex)) {
			pageIndex = "1";
		}
		Page page = new Page();
		page.setPageIndex(Integer.parseInt(pageIndex));
		page.setPageSize(Integer.parseInt(pageSize));
		// 查询数量
		int count = deviceService.countDevice(null, null, null, appKey);
		page = ToolUtil.getPage(count, page);
		try {

			List<Map> list = deviceService.selectDeviceFy(null, null, null, appKey, page.startRow(),
					page.getPageSize());
			// System.out.println(list.get(0));
			List<VoDevice> listDevice = new ArrayList<>();
			if (list != null && list.size() != 0) {
				for (int i = 0; i < list.size(); i++) {
					VoDevice voDevice = new VoDevice();
					String a_carryCode = (String) list.get(i).get("carry_code");
					String b_deviceId = (String) list.get(i).get("device_id");
					// 数据库int有null值时后台用Integer接收
					Integer c_isChan1 = (Integer) list.get(i).get("is_chan");
					String ischan = c_isChan1 + "";// int转String
					if (ischan == "1") {
						String c_isChan = "正向";
						voDevice.setIsChan(c_isChan);
					} else if (ischan == "2") {
						String c_isChan = "反向";
						voDevice.setIsChan(c_isChan);
					} else {
						String c_isChan = "暂无数据";
						voDevice.setIsChan(c_isChan);
					}

					String d_lineName = (String) list.get(i).get("line_name");
					String e_lineShort = (String) list.get(i).get("line_short");
					String f_gprsCode = (String) list.get(i).get("gprs_card");
					int id = (int) list.get(i).get("id");
					String idTest = id+"";
					String carryNo = (String) list.get(i).get("carry_no");
					String lineCode = (String) list.get(i).get("line_code");
					String deptCode = (String) list.get(i).get("dept_code");
					String deptName = (String) list.get(i).get("dept_name");
					String companyCode = (String) list.get(i).get("company_code");
					String companyName = (String) list.get(i).get("company_name");
					Date time = (Date) list.get(i).get("create_time");
					String createTime = UtilDate.getDateFormatter(time);

					int perAmount = (int) list.get(i).get("per_amount");
					Double sb = ((double) perAmount) / 100;
					String g_preMount = String.valueOf(sb);
					if(StringUtils.isEmpty(idTest)){
						voDevice.setId("暂无数据");
					}else {
						voDevice.setId(idTest);
					}
					if(StringUtils.isEmpty(carryNo)){
						voDevice.setCarryNo("暂无数据");
					}else{
						voDevice.setCarryNo(carryNo);
					}
					if(StringUtils.isEmpty(lineCode)){
						voDevice.setLineCode("暂无数据");
					}else{
						voDevice.setLineCode(lineCode);
					}
					if(StringUtils.isEmpty(deptCode)){
						voDevice.setDeptCode("暂无数据");
					}else{
						voDevice.setDeptCode(deptCode);
					}
					if(StringUtils.isEmpty(deptName)){
						voDevice.setDeptName("暂无数据");
					}else{
						voDevice.setDeptName(deptName);
					}
					if(StringUtils.isEmpty(companyCode)){
						voDevice.setCompanyCode("暂无数据");
					}else{
						voDevice.setCompanyCode(companyCode);
					}
					if(StringUtils.isEmpty(companyName)){
						voDevice.setCompanyName("暂无数据");
					}else{
						voDevice.setCompanyName(companyName);
					}
					if(StringUtils.isEmpty(createTime)){
						voDevice.setCreateTime("暂无数据");
					}else{
						voDevice.setCreateTime(createTime);
					}
					if (StringUtils.isEmpty(a_carryCode)) {
						voDevice.setCarryCode("暂无数据");
					} else {
						voDevice.setCarryCode(a_carryCode);
					}

					if (StringUtils.isEmpty(b_deviceId)) {
						voDevice.setDeviceId("暂无数据");
					} else {
						voDevice.setDeviceId(b_deviceId);
					}

					if (StringUtils.isEmpty(d_lineName)) {
						voDevice.setLineName("暂无数据");
					} else {
						voDevice.setLineName(d_lineName);
					}

					if (StringUtils.isEmpty(e_lineShort)) {
						voDevice.setLineShort("暂无数据");
					} else {
						voDevice.setLineShort(e_lineShort);
					}

					if (StringUtils.isEmpty(f_gprsCode)) {
						voDevice.setGprsCode("暂无数据");
					} else {
						voDevice.setGprsCode(f_gprsCode);
					}
					voDevice.setPreMount(g_preMount);
					listDevice.add(voDevice);
				}
				VoDevice head = new VoDevice();
				head.setDeviceId("设备号");
				head.setCarryCode("车牌号");
				head.setGprsCode("GPRS编号");
				head.setIsChan("正反向");
				head.setPreMount("单笔金额（元）");
				head.setLineName("线路名");
				head.setLineShort("线路简称");
                /*
				 * String[] head = new String[] { "车牌号", "设备号", "正反向", "线路名",
				 * "线路简称", "GPRS编号", "单笔金额（元）" };
				 */
				map.put("head", head);
				map.put("line", listDevice);
				map.put("page", page);
				voStatus.setCode(1);
				voStatus.setMessage("查询成功");
				map.put("status", voStatus);
			}
			map.put("head", "没有查询到相关数据");
			voStatus.setCode(0);
			voStatus.setMessage("没有查询到相关数据");
			map.put("status", voStatus);
		} catch (Exception e) {
			e.printStackTrace();
			voStatus.setCode(3);
			voStatus.setMessage("接口异常");
			map.put("status", voStatus);
		}
		mv.addObject("result", map);
		mv.addObject("appKey", appKey);
		return mv;
	}

	/**
	 * apk管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "/traffic/apk")
	public ModelAndView apkIndex(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/apk/apk");
		Map<String, Object> map = new HashMap<>();
		String appKey = request.getParameter("appKey");
		String pageIndex = request.getParameter("pageIndex");
		if (appKey != null && appKey != "") {

			String pageSize = "10";// 每一页的行数
			if (StringUtils.isEmpty(pageIndex)) {
				pageIndex = "1";
			}
			Page page = new Page();
			page.setPageIndex(Integer.parseInt(pageIndex));
			page.setPageSize(Integer.parseInt(pageSize));

			int count = appVersionService.newconntVersion(null, appKey);

			page = ToolUtil.getPage(count, page);
			try {
				List<Map> list = appVersionService.selectVersionFy(null, appKey, page.startRow(), page.getPageSize());
				List<VoVersion> versionList = new ArrayList<>();
				if (list != null && list.size() != 0) {
					for (int i = 0; i < list.size(); i++) {
						VoVersion voVersion = new VoVersion();
						String a_version = (String) list.get(i).get("version");
						String b_packagePath = (String) list.get(i).get("package_path");
						Date c_createTime = (Date) list.get(i).get("create_time");

						voVersion.setVersion(a_version);
						voVersion.setPackagePath(b_packagePath);
						voVersion.setCreateTime(c_createTime);

						versionList.add(voVersion);
					}

					// String[] head = new String[] { "版本号", "升级文件名", "上传时间" };
					VoVersion head = new VoVersion();
					head.setVersion("版本号");
					head.setPackagePath("升级文件名");
					map.put("head", head);
					map.put("line", versionList);
					map.put("page", page);
					voStatus.setCode(1);
					voStatus.setMessage("查询成功");
					map.put("status", voStatus);
				} else {
					map.put("head", "没有查到相关数据");
					voStatus.setCode(0);
					voStatus.setMessage("没有查到相关数据");
					map.put("status", voStatus);
				}
			} catch (Exception e) {
				e.printStackTrace();

			}
		}
		map.put("head", "无效appKey");
		mv.addObject("result", map);
		return mv;
	}

	/**
	 * 跳轉企业页面
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/traffic/company")
	public ModelAndView companyIndex(HttpServletRequest request) {

		ModelAndView mv = new ModelAndView("/company/company");
		Map<String, Object> map = new HashMap();
		// 获取请求参数
		String appKey = request.getParameter("appKey");
		String pageIndex = request.getParameter("pageIndex");
		String comCode = request.getParameter("comCode");
		String pageSize = "10";// 每一页的行数
		if (StringUtils.isEmpty(pageIndex)) {
			pageIndex = "1";
		}
		Page page = new Page();
		page.setPageIndex(Integer.parseInt(pageIndex));
		page.setPageSize(Integer.parseInt(pageSize));
		try {

			//查询总数量
			int count = companyService.getFindComCount(null, null, comCode);
			page = ToolUtil.getPage(count, page);

			List<Map<String, Object>> list = companyService.getFindCom(null, null, comCode, page.startRow(),
					page.getPageSize());
			if (list != null && list.size() != 0) {
				map.put("line", list);
				voStatus.setCode(1);
				voStatus.setMessage("查询成功");
				map.put("page", page);
				map.put("status", voStatus);
			}
			voStatus.setCode(0);
			voStatus.setMessage("查无数据");
			map.put("status", voStatus);

		} catch (Exception e) {
			e.printStackTrace();
		}
		mv.addObject("result", map);
		mv.addObject("comCode", comCode);
		mv.addObject("appKey", appKey);
		return mv;
	}

	/**
	 * company信息
	 *
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/company/info")
	public ModelAndView companyInfo(HttpServletRequest request) throws UnsupportedEncodingException {
		ModelAndView mv = new ModelAndView();
		String comId = request.getParameter("comId");
		String comCode = request.getParameter("comCode");
		String appKey = request.getParameter("appKey");
		Company company = null;

		if (null == comId) {
			company = new Company();
			mv.addObject("info", company);
			mv.setViewName("/company/companyAdd");
		} else {
			Map<String,Object> temp = companyService.getById(Integer.valueOf(comId));
			mv.addObject("info", temp);
			mv.setViewName("/company/companyInfo");
		}
		mv.addObject("comCode", comCode);
		mv.addObject("appKey", appKey);
		return mv;
	}
	/**
	 * company信息添加
	 *
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/company/add")
	public ModelAndView companyAdd(HttpServletRequest request) throws UnsupportedEncodingException {
		String accountName = request.getParameter("accountName");
		String accountChinese = request.getParameter("accountChinese");
		String accountPassword = request.getParameter("accountPassword");
		String comName = request.getParameter("comName");
		String comAddress = request.getParameter("comAddress");
		String account = request.getParameter("account");
		String passwd = request.getParameter("passwd");
		String comCode = request.getParameter("comCode");
		String appKeyTemp = request.getParameter("appKey");
		String appId = request.getParameter("appId");
		String privateKey = request.getParameter("privateKey");

		ModelAndView mv = new ModelAndView("redirect:/traffic/company?&comCode="+comCode+"&appKey="+appKeyTemp);

		Map<String, Object> map = new HashMap<>();
		try {
			do {
				if (!StringUtils.isNotBlank(comCode)) {
					voStatus.setCode(0);
					voStatus.setMessage("增加失败，无效comCode");
					map.put("status", voStatus);
					break;
				}
				Company company = null;
				Account account1 = null;
                AlipayEnterpriseAccount alipayEnterpriseAccount = null;
				Sftp sftp = null;
				String appKey = AppKeyUtil.getAppKey();
				if (!StringUtils.isAnyBlank(accountName, accountPassword)) {
					account1 = accountService.getByAccountName(accountName);
					if (account1 != null) {
						voStatus.setCode(0);
						voStatus.setMessage("增加失败，accountName已存在");
						map.put("status", voStatus);
						break;
					}
					account1 = new Account();
					account1.setAccountName(accountName);
					account1.setAccountPassword(MD5Util.GetMD5Code(accountPassword));
					account1.setComCode(comCode + "-" + appKey);
					account1.setAppKey(appKey);
					account1.setAccountChinese(accountChinese);
				}
				if (!StringUtils.isAnyBlank(account, passwd)) {
					sftp = sftpService.getByAccount(account);
					if (sftp != null) {
						voStatus.setCode(0);
						voStatus.setMessage("增加失败，account已存在");
						map.put("status", voStatus);
						break;
					}
					sftp = new Sftp();
					sftp.setAccount(account);
					sftp.setPasswd(passwd);
					sftp.setComCode(comCode + "-" + appKey);
					sftp.setAppKey(appKey);
				}
				if (!StringUtils.isAnyBlank(comName, comAddress)) {
					company = new Company();
					company.setComName(comName);
					company.setComCode(comCode + "-" + appKey);
					company.setComParentCode(comCode);
					company.setComAddress(comAddress);
					company.setAppKey(appKey);
				}
                if(!StringUtils.isAnyBlank(appId,privateKey)){
                    alipayEnterpriseAccount = new AlipayEnterpriseAccount();
                    alipayEnterpriseAccount.setAppKey(appKey);
                    alipayEnterpriseAccount.setCreateDate(new Date());
                    alipayEnterpriseAccount.setAppId(appId);
                    alipayEnterpriseAccount.setPrivateKey(privateKey);
                    alipayEnterpriseAccount.setGateWay("https://openapi.alipay.com/gateway.do");
                    alipayEnterpriseAccount.setStringCharset("GBK");
                }
                companyService.addCompany(company, sftp, account1,alipayEnterpriseAccount);
				voStatus.setCode(1);
				voStatus.setMessage("增加成功");
				map.put("status", voStatus);
			} while (false);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return mv;
	}
	/**
	 * company信息修改
	 *
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/company/modify")
	public ModelAndView companyModify(HttpServletRequest request) throws UnsupportedEncodingException {
		String accountName = request.getParameter("accountName");
		String accountChinese = request.getParameter("accountChinese");
		String accountPassword = request.getParameter("accountPassword");
		String comName = request.getParameter("comName");
		String comAddress = request.getParameter("comAddress");
		String account = request.getParameter("account");
		String passwd = request.getParameter("passwd");
		String comCode = request.getParameter("comCode");
		String appKeyTemp = request.getParameter("appKey");
		String comId = request.getParameter("comId");
		String accountId = request.getParameter("accountId");
		String sftpId = request.getParameter("sftpId");

		ModelAndView mv = new ModelAndView("redirect:/traffic/company?&comCode="+comCode+"&appKey="+appKeyTemp);
		Map<String, Object> map = new HashMap<>();
		try {
			do {
				if (StringUtils.isNotBlank(comId)) {
					Company company = companyService.getUpdateById(Integer.parseInt(comId));
					if(StringUtils.isNotBlank(comAddress)){
						comAddress = URLDecoder.decode(comAddress,"UTF-8");
						company.setComAddress(comAddress);
					}
					if(StringUtils.isNotBlank(comName)){
						comName = URLDecoder.decode(comName,"UTF-8");
						company.setComName(comName);
					}
					companyService.updateCompany(company);
				}
				if (StringUtils.isNotBlank(accountId)) {
					Account account1 = accountService.getById(Integer.parseInt(accountId));
					if(StringUtils.isNotBlank(accountName)){
						account1.setAccountName(accountName);
					}
					if(StringUtils.isNotBlank(accountPassword)){
						account1.setAccountPassword(MD5Util.GetMD5Code(accountPassword));
					}
					if(StringUtils.isNotBlank(accountChinese)){
						accountChinese = URLDecoder.decode(accountChinese,"UTF-8");
						account1.setAccountChinese(accountChinese);
					}
					companyService.updateAccount(account1);
				}
				if (StringUtils.isNotBlank(sftpId)) {
					Sftp sftp = sftpService.getById(Integer.parseInt(sftpId));
					if(StringUtils.isNotBlank(account)){
						sftp.setAccount(account);
					}
					if(StringUtils.isNotBlank(passwd)){
						sftp.setPasswd(passwd);
					}
					companyService.updateSftp(sftp);
				}
				voStatus.setCode(1);
				voStatus.setMessage("修改成功");
				map.put("status", voStatus);

			} while (false);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return mv;
	}
	/**
	 * company信息修改
	 *
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/company/delete")
	public ModelAndView companyDelete(HttpServletRequest request) throws UnsupportedEncodingException {

		String comCode = request.getParameter("comCode");
		String appKeyTemp = request.getParameter("appKey");
		String comId = request.getParameter("comId");
		String accountId = request.getParameter("accountId");
		String sftpId = request.getParameter("sftpId");

		ModelAndView mv = new ModelAndView("redirect:/traffic/company?&comCode="+comCode+"&appKey="+appKeyTemp);
		Map<String, Object> map = new HashMap<>();
		try {
			do {
				if(!StringUtils.isNotBlank(comId) && !StringUtils.isNotBlank(sftpId) && !StringUtils.isNotBlank(accountId)) {
					voStatus.setCode(1);
					voStatus.setMessage("删除失败,无法获取需删除信息！");
					map.put("status", voStatus);
					break;
				}
				if (StringUtils.isNotBlank(comId)) {
					companyService.deleteCompany(Integer.parseInt(comId));
				}
				if (StringUtils.isNotBlank(sftpId)) {
					companyService.deleteSftp(Integer.parseInt(sftpId));
				}
				if (StringUtils.isNotBlank(accountId)) {
					companyService.deleteAccount(Integer.parseInt(accountId));
				}
				voStatus.setCode(1);
				voStatus.setMessage("删除成功");
				map.put("status", voStatus);
			} while (false);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mv;
	}

	/**
	 * 跳轉员工页面
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/traffic/employee")
	public ModelAndView employeeIndex(HttpServletRequest request) {

		ModelAndView mv = new ModelAndView("/baseData/employee");
		Map<String, Object> map = new HashMap();
		// 获取请求参数
		String appKey = request.getParameter("appKey");
		String pageIndex = request.getParameter("pageIndex");
		// 查询员工信息
		String pageSize = "10";// 每一页的行数
		if (StringUtils.isEmpty(pageIndex)) {
			pageIndex = "1";
		}
		Page page = new Page();
		page.setPageIndex(Integer.parseInt(pageIndex));
		page.setPageSize(Integer.parseInt(pageSize));
		// 分页总数量
		int count = employeeService.getEmployeeCount(null, null, null, null, appKey);
		page = ToolUtil.getPage(count, page);

		try {
			// 分页查询
			List<Employee> list = employeeService.getEmployeeList(null, null, null, null, appKey, page.startRow(),
					page.getPageSize());
			if (list != null && list.size() != 0) {
				// 初始化VoEmployee
				List<VoEmployee> voEmployeeList = new ArrayList<>();
				for (Employee employee : list) {
					VoEmployee voEmployee = new VoEmployee();
					voEmployee.setEmpCode(employee.getEmpCode());
					voEmployee.setEmpName(employee.getEmpName());
					voEmployee.setGender(employee.getGender());
					voEmployee.setTelephone(employee.getTelephone());
					voEmployee.setCompanyName(employee.getEmpName());
					voEmployeeList.add(voEmployee);
				}

				VoEmployee head = new VoEmployee();
				head.setEmpCode("员工编号");
				head.setEmpName("员工姓名");
				head.setGender("员工性别");
				head.setTelephone("员工联系方式");
				head.setCompanyName("公司名称");
				map.put("page", page);
				map.put("head", head);
				map.put("line", list);
				voStatus.setCode(1);
				voStatus.setMessage("查询成功");
				map.put("status", voStatus);
			}
			voStatus.setCode(0);
			voStatus.setMessage("查无数据");
			map.put("status", voStatus);
		} catch (Exception e) {
			e.printStackTrace();
		}

		// 返回数据页面
		mv.addObject("result", map);
		return mv;
	}

	/**
	 * 跳轉车辆页面
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/traffic/carry")
	public ModelAndView carryIndex(HttpServletRequest request) {

		ModelAndView mv = new ModelAndView("/baseData/carry");
		Map<String, Object> map = new HashMap();
		// 获取请求参数
		String appKey = request.getParameter("appKey");
		String pageIndex = request.getParameter("pageIndex");
		// 查询员工信息
		String pageSize = "10";// 每一页的行数
		if (StringUtils.isEmpty(pageIndex)) {
			pageIndex = "1";
		}
		Page page = new Page();
		page.setPageIndex(Integer.parseInt(pageIndex));
		page.setPageSize(Integer.parseInt(pageSize));
		// 分页总数量
		int count = carryservice.getCarryCount(null, null, null, null, appKey);
		page = ToolUtil.getPage(count, page);

		try {
			// 初始化VoCarry
			List<VoCarry> voCarryList = new ArrayList<>();
			// 分页查询
			List<Carry> list = carryservice.getCarryList(null, null, null, null, appKey, page.startRow(),
					page.getPageSize());
			if (list != null && list.size() != 0) {
				for (Carry carry : list) {
					VoCarry voCarry = new VoCarry();
					double amount = carry.getUnitPrice();
					String unitPrice = String.valueOf(amount / 100);
					voCarry.setCarryCode(carry.getCarryCode());
					voCarry.setCarryName(carry.getCarryNo());
					voCarry.setDeptCode(carry.getDeptCode());
					voCarry.setDeptName(carry.getDeptName());
					voCarry.setCompanyName(carry.getCompanyName());
					voCarry.setIsProducing(carry.getIsProducing());
					voCarry.setLineCode(carry.getLineCode());
					voCarry.setLineName(carry.getLineName());
					voCarry.setUnitPrice(unitPrice);
					voCarryList.add(voCarry);
				}

				VoCarry head = new VoCarry();
				head.setCarryCode("车编号");
				head.setCarryName("自编号");
				head.setDeptCode("部门编号");
				head.setDeptName("部门名称");
				head.setCompanyName("公司名称");
				head.setIsProducing("是否运营");
				head.setLineCode("线路编号");
				head.setLineName("线路名称");
				head.setUnitPrice("票价（元）");

				map.put("head", head);
				map.put("line", list);
				map.put("page", page);
				voStatus.setCode(1);
				voStatus.setMessage("查询成功");
				map.put("status", voStatus);
			}
			voStatus.setCode(0);
			voStatus.setMessage("查无数据");
			map.put("status", voStatus);
		} catch (Exception e) {
			e.printStackTrace();
		}
		// 返回数据页面
		mv.addObject("result", map);
		return mv;
	}

	/**
	 * 跳轉线路页面
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/traffic/line")
	public ModelAndView lineIndex(HttpServletRequest request) {

		ModelAndView mv = new ModelAndView("/baseData/line");
		Map<String, Object> map = new HashMap();
		// 获取请求参数
		String appKey = request.getParameter("appKey");
		String pageIndex = request.getParameter("pageIndex");
		String pageSize = "10";// 每一页的行数
		if (StringUtils.isEmpty(pageIndex)) {
			pageIndex = "1";
		}
		Page page = new Page();
		page.setPageIndex(Integer.parseInt(pageIndex));
		page.setPageSize(Integer.parseInt(pageSize));
		// 分页总数量
		int count = lineService.getLineCount(null, null, appKey);
		page = ToolUtil.getPage(count, page);
		try {
			// 分页查询
			List<Line> list = lineService.getLineList(null, null, appKey, page.startRow(), page.getPageSize());
			List<VoLine> voLineList = new ArrayList<>();
			if (list != null && list.size() != 0) {
				for (Line line : list) {
					VoLine voLine = new VoLine();
					voLine.setCategory(line.getCategory());
					voLine.setCircle(line.getCircle());
					voLine.setCompanyName(line.getCompanyName());
					voLine.setDeptCode(line.getDeptCode());
					voLine.setDeptName(line.getDeptName());
					voLine.setGprsCode(line.getGpsCode());
					voLine.setLineCode(line.getLineCode());
					voLine.setLineName(line.getLineName());
					voLine.setLineShort(line.getLineShort());
					voLine.setLineCount(line.getLineCount());
					voLineList.add(voLine);
				}

				VoLine head = new VoLine();
				head.setCategory("线路分类");
				head.setCircle("是否循环线路");
				head.setCompanyName("公司名称");
				head.setDeptCode("部门编号");
				head.setDeptName("部门名称");
				head.setGprsCode("GPS车载机上的对应编号");
				head.setLineCode("线路编号");
				head.setLineName("线路名称");
				head.setLineShort("线路短号");
				head.setLineCount("配车/船数");
				map.put("head", head);
				map.put("line", list);
				voStatus.setCode(1);
				voStatus.setMessage("查询成功");
				map.put("status", voStatus);
			}
			voStatus.setCode(0);
			voStatus.setMessage("查无数据");
			map.put("status", voStatus);
		} catch (Exception e) {
			e.printStackTrace();
		}

		// 返回数据页面
		mv.addObject("result", map);
		return mv;
	}

	/**
	 * 白名单首页
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/traffic/white")
	public ModelAndView whiteIndex(HttpServletRequest request) {

		ModelAndView mv = new ModelAndView("/system/white");
		Map<String, Object> map = new HashMap<>();
		// 获取请求参数
		String appKey = request.getParameter("appKey");
		String pageIndex = request.getParameter("pageIndex");
		String pageSize = "10";// 每一页的行数
		if (StringUtils.isEmpty(pageIndex)) {
			pageIndex = "1";
		}

		Page page = new Page();
		page.setPageIndex(Integer.parseInt(pageIndex));
		page.setPageSize(Integer.parseInt(pageSize));
		try {
			Map<String, Object> conditions = new HashMap<>();
			conditions.put("startRow", page.startRow());

			conditions.put("appKey", appKey);
			if (null != pageSize) {
				conditions.put("pageSize", Integer.valueOf(pageSize));
			}
			int count = whiteListService.getFindWhiteListCount(conditions);
			page = ToolUtil.getPage(count, page);
			List<WhiteList> list = whiteListService.getFindWhiteList(conditions);
			List<VoWhiteList> voWhiteListList = new ArrayList<>();
			if (list != null && list.size() != 0) {
				for (WhiteList whiteList : list) {
					VoWhiteList voWhiteList = new VoWhiteList();
					voWhiteList.setWlId(whiteList.getWlId());
					voWhiteList.setUserId(whiteList.getUserId());
					voWhiteList.setUserName(whiteList.getUserName());
					double amountindex = whiteList.getPrice();
					voWhiteList.setPrice(amountindex / 100 + "");
					voWhiteList.setStatus(whiteList.getStatus());
					Date date = whiteList.getCreateTime();
					voWhiteList.setCreateTime(UtilDate.getDateFormatter(date));
					voWhiteListList.add(voWhiteList);
				}
				VoWhiteList head = new VoWhiteList();
				head.setUserId("支付宝ID");
				head.setUserName("用户名");
				// head.setStatus("状态");
				head.setCreateTime("添加时间");
				map.put("head", head);
				map.put("line", voWhiteListList);
				map.put("page", page);
				voStatus.setCode(1);
				voStatus.setMessage("查询成功");
				map.put("status", voStatus);
			}
			voStatus.setCode(0);
			voStatus.setMessage("查无数据");
			map.put("status", voStatus);
		} catch (Exception e) {
			e.printStackTrace();
		}

		// 返回数据页面
		mv.addObject("result", map);
		return mv;
	}

	/**
	 * 设备信息
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/equipment/info")
	public ModelAndView equipmentInfo(HttpServletRequest request) throws UnsupportedEncodingException {
		ModelAndView mv = new ModelAndView();
		String deviceId = request.getParameter("deviceId");
		String appKey = request.getParameter("appKey");
		String comCode = request.getParameter("comCode");
		Device device = new Device();
		if (deviceId != null) {
			device = deviceService.getDevice(deviceId);
			mv.setViewName("/company/equipmentInfo");
		} else {
			mv.setViewName("/company/equipmentAdd");
		}
		mv.addObject("info", device);
		mv.addObject("appKey", appKey);
		mv.addObject("comCode", comCode);
		return mv;
	}

	/**
	 * 设备修改
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/equipment/modify", method = RequestMethod.POST)
	public ModelAndView equipmentModify(HttpServletRequest request) throws UnsupportedEncodingException {

		String carryCode = request.getParameter("carryCode");
		String deviceId = request.getParameter("deviceId");
		String oldDeviceId = request.getParameter("oldDeviceId");
		String isChan = request.getParameter("isChan");
		String lineName = request.getParameter("lineName");
		String lineShort = request.getParameter("lineShort");
		String gprsCard = request.getParameter("gprsCard");
		String perAmount = request.getParameter("perAmount");
		String appKey = request.getParameter("appKey");
		String comCode = request.getParameter("comCode");
		Device device = deviceService.getDevice(oldDeviceId);
		ModelAndView mv = new ModelAndView("redirect:/traffic/equipment?appKey=" + appKey+"&comCode="+comCode);
		if (device != null) {
			if (carryCode != null) {
				device.setCarryCode(carryCode);
			}
			if (lineName != null) {
				lineName = URLDecoder.decode(lineName, "UTF-8");
				device.setLineName(lineName);
			}
			if (gprsCard != null) {
				device.setGprsCard(gprsCard);
			}
			if (lineShort != null) {
				device.setLineShort(lineShort);
			}
			if (deviceId != null) {
				device.setDeviceId(deviceId);
			}
			/*
			 * if (isChan.equals("正向") ) { int isChans = 1;
			 * device.setIsChan(isChans); } else if (isChan.equals("反向") ) { int
			 * isChans = 2; device.setIsChan(isChans); }
			 */
			if (perAmount != null) {
				double amountindex = Double.parseDouble(perAmount) * 100;
				String amountsecount = StringUtils.split(String.valueOf(amountindex), ".")[0];
				device.setPerAmount(Integer.parseInt(amountsecount));
			}
		}
		device.setUpdateTime(new Date());
		deviceService.updateDevice(device);
		mv.addObject("appKey", appKey);
		mv.addObject("comCode", comCode);
		return mv;
	}

	/**
	 * 设备新增
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/equipment/add", method = RequestMethod.POST)
	public ModelAndView equimentAdd(HttpServletRequest request) throws UnsupportedEncodingException {

		String carryCode = request.getParameter("carryCode");
		String deviceId = request.getParameter("deviceId");
		String isChan = request.getParameter("isChan");
		String lineName = request.getParameter("lineName");
		String lineShort = request.getParameter("lineShort");
		String gprsCard = request.getParameter("gprsCard");
		String perAmount = request.getParameter("perAmount");
		String appKey = request.getParameter("appKey");
		String comCode = request.getParameter("comCode");
		Device device = null;
		ModelAndView mv = new ModelAndView("redirect:/traffic/equipment?appKey=" + appKey+"&comCode"+comCode);
		if (device == null) {
			device = new Device();
			if (carryCode != null) {
				device.setCarryCode(carryCode);
			}
			if (lineName != null) {
				lineName = URLDecoder.decode(lineName, "UTF-8");
				device.setLineName(lineName);
			}
			if (gprsCard != null) {
				device.setGprsCard(gprsCard);
			}
			if (lineShort != null) {
				device.setLineShort(lineShort);
			}
			if (deviceId != null) {
				device.setDeviceId(deviceId);
			}
			/*
			 * if (isChan.equals("正向") ) { int isChans = 1;
			 * device.setIsChan(isChans); } else if (isChan.equals("反向") ) { int
			 * isChans = 2; device.setIsChan(isChans); }
			 */
			if (appKey != null) {
				device.setAppKey(appKey);
			}
			if (perAmount != null) {
				double amountindex = Double.parseDouble(perAmount) * 100;
				String amountsecount = StringUtils.split(String.valueOf(amountindex), ".")[0];
				device.setPerAmount(Integer.parseInt(amountsecount));
			}
		}
		device.setCreateTime(new Date());
		device.setUpdateTime(new Date());
		deviceService.addDevice(device);
		mv.addObject("appKey", appKey);
		mv.addObject("comCode", comCode);
		return mv;
	}

	/**
	 * 设备删除
	 *
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/equipment/delete", method = RequestMethod.GET)
	public ModelAndView equipmentDelete(HttpServletRequest request) throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		Map<String,Object> map = new HashMap<>();
		String id = request.getParameter("id");
		String appKey = request.getParameter("appKey");
		String comCode = request.getParameter("comCode");
		ModelAndView mv = new ModelAndView();
		try {
			do {
				if(!StringUtils.isNotBlank(id)){
					voStatus.setCode(0);
					voStatus.setMessage("删除失败");
					map.put("status", voStatus);
					break;
				}
				deviceService.deleteDevice(Integer.parseInt(id));
				voStatus.setCode(1);
				voStatus.setMessage("删除成功");
				map.put("status", voStatus);
				break;
			}while (false);
		}catch (Exception e){
			e.printStackTrace();
		}

		return mv;
	}

	/**
	 * 白名单修改
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/white/modify", method = RequestMethod.POST)
	public ModelAndView whiteModify(HttpServletRequest request) throws UnsupportedEncodingException {

		String userId = request.getParameter("userId");
		String userName = request.getParameter("userName");
		String price = request.getParameter("price");
		String status = request.getParameter("status");
		String wlId = request.getParameter("wlId");
		String appKey = request.getParameter("appKey");
		ModelAndView mv = new ModelAndView("redirect:/traffic/white?appKey=" + appKey);
		WhiteList whiteList = null;
		if (null != wlId) {
			whiteList = whiteListService.getById(Integer.valueOf(wlId));
		}
		if (whiteList != null) {
			if (StringUtils.isNotBlank(userId)) {
				whiteList.setUserId(userId);
			}
			if (StringUtils.isNoneBlank(userName)) {
				whiteList.setUserName(userName);
			}
			if (StringUtils.isNoneBlank(price)) {
				double amountindex = Double.parseDouble(price) * 100;
				whiteList.setPrice((int) amountindex);
			}
			if (null != status) {
				switch (status) {
				case "normal":
					whiteList.setStatus(0);
					break;
				case "unable":
					whiteList.setStatus(1);
					break;
				default:
					whiteList.setStatus(0);
					break;
				}

			}
			whiteListService.updateWhiteList(whiteList);

		}
		mv.addObject("appKey", appKey);
		return mv;
	}
	
	/**
	 * 白名单修改
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/white/add", method = RequestMethod.POST)
	public ModelAndView whiteAdd(HttpServletRequest request) throws UnsupportedEncodingException {

		String userId = request.getParameter("userId");
		String userName = request.getParameter("userName");
		String price = request.getParameter("price");
		String status = request.getParameter("status");
		String wlId = request.getParameter("wlId");
		String appKey = request.getParameter("appKey");
		ModelAndView mv = new ModelAndView("redirect:/traffic/white?appKey=" + appKey);
		WhiteList whiteList = new WhiteList();
		if (whiteList != null) {
			if (StringUtils.isNotBlank(userId)) {
				whiteList.setUserId(userId);
			}
			if (StringUtils.isNoneBlank(userName)) {
				whiteList.setUserName(userName);
			}
			if (StringUtils.isNoneBlank(price)) {
				double amountindex = Double.parseDouble(price) * 100;
				whiteList.setPrice((int) amountindex);
			}
			whiteList.setStatus(0);
			whiteList.setAppKey(appKey);
			whiteList.setCreateTime(new Date());
			whiteListService.addWhiteList(whiteList);

		}
		mv.addObject("appKey", appKey);
		return mv;
	}
	/**
	 * apk管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "/traffic/app/outer")
	public ModelAndView appOuterIndex(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/app/appOuter");
		Map<String, Object> map = new HashMap<>();
		String appKey = request.getParameter("appKey");
		String pageIndex = request.getParameter("pageIndex");
		String pageSize = "10";// 每一页的行数
		if (StringUtils.isEmpty(pageIndex)) {
			pageIndex = "1";
		}
		Page page = new Page();
		page.setPageIndex(Integer.parseInt(pageIndex));
		page.setPageSize(Integer.parseInt(pageSize));

		try {
			Map<String, Object> conditions = new HashMap<>();
			conditions.put("anarchy", 1);
			conditions.put("appKey", appKey);
			int count = vehAppCarryService.getAppCarryCount(conditions);
			page = ToolUtil.getPage(count, page);
			conditions.put("pageSize", page.getPageSize());
			conditions.put("startRow", page.startRow());

			List<VehAppCarry> list = vehAppCarryService.getAppCarry(conditions);
			if (list != null && list.size() != 0) {
				List<VoVehAppCarry> voVehAppCarryList = new ArrayList<>();
				for (VehAppCarry vehAppCarry : list) {
					VoVehAppCarry voVehAppCarry = new VoVehAppCarry();
					voVehAppCarry.setCode(vehAppCarry.getCode());
					voVehAppCarry.setLineName(vehAppCarry.getLineName());
					voVehAppCarry.setRegCode(vehAppCarry.getRegCode());
					voVehAppCarry.setDataid(vehAppCarry.getDataid());
					voVehAppCarry.setCreateTime(UtilDate.getDateFormatter(vehAppCarry.getCreateTime()));
					voVehAppCarryList.add(voVehAppCarry);
				}
				VoVehAppCarry head = new VoVehAppCarry();
				head.setCode("自编号");
				head.setCreateTime("添加世间");
				head.setLineName("线路名");
				head.setRegCode("车牌号");
				map.put("head", head);
				map.put("line", voVehAppCarryList);
				map.put("page", page);
				voStatus.setCode(1);
				voStatus.setMessage("查询成功");
				map.put("status", voStatus);
			}
			voStatus.setCode(0);
			voStatus.setMessage("暂无数据");
			map.put("status", voStatus);
		} catch (Exception e) {
			e.printStackTrace();
		}

		mv.addObject("result", map);
		return mv;
	}
	/**
	 * app
	 * 录入列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "/traffic/app/inner")
	public ModelAndView appInnerIndex(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/app/appInner");
		Map<String, Object> map = new HashMap<>();
		String appKey = request.getParameter("appKey");
		String pageIndex = request.getParameter("pageIndex");
		String pageSize = "10";// 每一页的行数
		if (StringUtils.isEmpty(pageIndex)) {
			pageIndex = "1";
		}
		Page page = new Page();
		page.setPageIndex(Integer.parseInt(pageIndex));
		page.setPageSize(Integer.parseInt(pageSize));

		try {

			Map<String, Object> conditions = new HashMap<>();
			conditions.put("appKey", appKey);

			int count = vehAppDeviceService.getFindVehAppDeviceCount(conditions);
			page = ToolUtil.getPage(count, page);

			conditions.put("pageSize", page.getPageSize());
			conditions.put("startRow", page.startRow());

			List<VehAppDevice> list = vehAppDeviceService.getFindVehAppDevice(conditions);
			if (list != null && list.size() != 0) {
				List<VoVehAppDevice> voVehAppDeviceList = new ArrayList<>();
				for (VehAppDevice vehAppDevice : list) {
					VoVehAppDevice voVehAppDevice = new VoVehAppDevice();
					voVehAppDevice.setId(vehAppDevice.getId());
					voVehAppDevice.setAddress(vehAppDevice.getAddress());
					voVehAppDevice.setDeviceId(vehAppDevice.getDeviceId());
					voVehAppDevice.setVehNo(vehAppDevice.getVehNo());
					voVehAppDevice.setVehCode(vehAppDevice.getVehCode());
					voVehAppDevice.setTelephone(vehAppDevice.getTelephone());
					voVehAppDevice.setNoteDetails(vehAppDevice.getNoteDetails());
					voVehAppDevice.setCreateTime(UtilDate.getDateFormatter(vehAppDevice.getCreateTime()));
					Integer note = vehAppDevice.getNote();
					String ischan = note + "";
					String notes = null;
					if (ischan.equals("1")) {
						notes = "换机具";
					} else if (ischan.equals("2")) {
						notes = "换流量卡";
					} else if (ischan.equals("3")) {
						notes = "其他";
					}else{
						notes = "暂无数据";
					}
					voVehAppDevice.setNote(notes);
					voVehAppDeviceList.add(voVehAppDevice);
				}
				VoVehAppDevice head = new VoVehAppDevice();
				head.setAddress("安装地址");
				head.setCreateTime("安装时间");
				head.setDeviceId("机具编号");
				head.setNote("备注类型");
				head.setNoteDetails("备注内容");
				head.setTelephone("安装人手机号码");
				head.setVehNo("车牌号");
				map.put("head", head);
				map.put("page", page);
				map.put("line", voVehAppDeviceList);
				voStatus.setCode(1);
				voStatus.setMessage("查询成功");
				map.put("status", voStatus);
			}
			voStatus.setCode(0);
			voStatus.setMessage("暂无数据");
			map.put("status", voStatus);
		} catch (Exception e) {
			e.printStackTrace();
		}

		mv.addObject("result", map);
		return mv;
	}
	/**
	 * app
	 * 录入列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "/traffic/app/history")
	public ModelAndView appHistoryIndex(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/app/appHistory");
		String pageIndex = request.getParameter("pageIndex");
		String appKey = request.getParameter("appKey");
		Map<String, Object> map = new HashMap<>();
		String pageSize = "10";// 每一页的行数
		if (StringUtils.isEmpty(pageIndex)) {
			pageIndex = "1";
		}
		Page page = new Page();
		page.setPageIndex(Integer.parseInt(pageIndex));
		page.setPageSize(Integer.parseInt(pageSize));

		try {

			Map<String, Object> conditions = new HashMap<>();
			conditions.put("appKey", appKey);

			int count = vehAppOldDeviceService.getFindVehAppOldDeviceCount(conditions);
			page = ToolUtil.getPage(count, page);

			conditions.put("pageSize", page.getPageSize());
			conditions.put("startRow", page.startRow());

			List<VehAppOldDevice> list = vehAppOldDeviceService.getFindVehAppOldDevice(conditions);
			if (list != null && list.size() != 0) {
				List<VoVehAppDevice> voVehAppDeviceList = new ArrayList<>();
				for (VehAppOldDevice vehAppOldDevice : list) {
					VoVehAppDevice voVehAppDevice = new VoVehAppDevice();
					voVehAppDevice.setTelephone(vehAppOldDevice.getTelephone());
					voVehAppDevice.setId(vehAppOldDevice.getId());
					voVehAppDevice.setAddress(vehAppOldDevice.getAddress());
					voVehAppDevice.setDeviceId(vehAppOldDevice.getDeviceId());
					voVehAppDevice.setVehNo(vehAppOldDevice.getVehNo());
					voVehAppDevice.setVehCode(vehAppOldDevice.getVehCode());
					voVehAppDevice.setCreateTime(UtilDate.getDateFormatter(vehAppOldDevice.getCreateTime()));
					voVehAppDeviceList.add(voVehAppDevice);
				}
				VoVehAppDevice head = new VoVehAppDevice();
				head.setAddress("安装地址");
				head.setCreateTime("安装时间");
				head.setDeviceId("机具编号");
				head.setNote("备注类型");
				head.setVehCode("自编号");
				head.setNoteDetails("备注内容");
				head.setTelephone("安装人手机号码");
				head.setVehNo("车牌号");
				map.put("head", head);
				map.put("page", page);
				map.put("line", voVehAppDeviceList);
				voStatus.setCode(1);
				voStatus.setMessage("查询成功");
				map.put("status", voStatus);
			}
			voStatus.setCode(0);
			voStatus.setMessage("暂无数据");
			map.put("status", voStatus);
		} catch (Exception e) {
			e.printStackTrace();
		}

		mv.addObject("result", map);
		return mv;
	}

	/**
	 * appOuter信息
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/app/outer/info")
	public ModelAndView appOuterInfo(HttpServletRequest request) throws UnsupportedEncodingException {
		ModelAndView mv = new ModelAndView();
		String dataid = request.getParameter("dataid");
		String appKey = request.getParameter("appKey");
		VehAppCarry vehAppCarry = new VehAppCarry();

		if (dataid != null) {
			vehAppCarry = vehAppCarryService.getById(Integer.valueOf(dataid));
			mv.setViewName("/app/appOuterInfo");
		} else {
			mv.setViewName("/app/appOuterAdd");
		}
		mv.addObject("info", vehAppCarry);
		mv.addObject("appKey", appKey);
		return mv;
	}
	

	/**
	 * appInner信息
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/app/inner/info")
	public ModelAndView appInnerInfo(HttpServletRequest request) throws UnsupportedEncodingException {
		ModelAndView mv = new ModelAndView();
		String id = request.getParameter("id");
		String appKey = request.getParameter("appKey");
		VehAppDevice vehAppDevice = null;
		if(StringUtils.isNotBlank(id)){
			vehAppDevice = vehAppDeviceService.getById(Integer.valueOf(id));
		}
		
		mv.setViewName("/app/appInnerInfo");
		mv.addObject("info", vehAppDevice);
		mv.addObject("appKey", appKey);
		return mv;
	}
	/**
	 * appOuter信息
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/app/outer/modify")
	public ModelAndView appOuterModify(HttpServletRequest request) throws UnsupportedEncodingException {
		String dataid = request.getParameter("dataid");
		String appKey = request.getParameter("appKey");
		String regCode = request.getParameter("regCode");
		String lineName = request.getParameter("lineName");
		String code = request.getParameter("code");
		String status = request.getParameter("status");
		ModelAndView mv = new ModelAndView("redirect:/traffic/app/outer?appKey=" + appKey);
		VehAppCarry vehAppCarry = vehAppCarryService.getById(Integer.valueOf(dataid));
		if (vehAppCarry != null) {
			if (StringUtils.isNotBlank(regCode)) {
				vehAppCarry.setRegCode(URLDecoder.decode(regCode, "utf-8"));
			}
			if (StringUtils.isNotBlank(lineName)) {
				vehAppCarry.setLineName(URLDecoder.decode(lineName, "utf-8"));
			}
			if (StringUtils.isNotBlank(code)) {
				vehAppCarry.setCode(code);
			}
			if (StringUtils.isNotBlank(status)) {
				vehAppCarry.setStatus(Integer.valueOf(status));;
			}
			vehAppCarryService.updateVehAppCarry(vehAppCarry);
		}
		mv.addObject("appKey", appKey);
		return mv;
	}

	/**
	 * appOuter信息
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/app/outer/add")
	public ModelAndView appOuterAdd(HttpServletRequest request) throws UnsupportedEncodingException {
		String dataid = request.getParameter("dataid");
		String appKey = request.getParameter("appKey");
		String regCode = request.getParameter("regCode ");
		String lineName = request.getParameter("lineName ");
		String code = request.getParameter("code ");
		ModelAndView mv = new ModelAndView("redirect:/traffic/app/outer?appKey=" + appKey);
		VehAppCarry vehAppCarry = new VehAppCarry();
		
		if (StringUtils.isNotBlank(regCode)) {
			vehAppCarry.setRegCode(URLDecoder.decode(regCode, "utf-8"));
		}
		if (StringUtils.isNotBlank(lineName)) {
			vehAppCarry.setLineName(URLDecoder.decode(lineName, "utf-8"));
		}
		if (StringUtils.isNotBlank(code)) {
			vehAppCarry.setCode(code);
		}
		vehAppCarry.setStatus(1);
		vehAppCarry.setAppKey(appKey);
		vehAppCarry.setCreateTime(new Date());
		vehAppCarryService.addVehAppCarry(vehAppCarry);
		mv.addObject("appKey", appKey);
		return mv;
	}
	/**
	 * appInner修改
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/traffic/app/inner/modify")
	public ModelAndView appInnerModify(HttpServletRequest request) throws UnsupportedEncodingException {
		String note = request.getParameter("note");
		String noteDetails = request.getParameter("noteDetails");
		String id = request.getParameter("id");
		String appKey = request.getParameter("appKey");
		ModelAndView mv = new ModelAndView("redirect:/traffic/app/inner?appKey=" + appKey);
		VehAppDevice vehAppDevice = null;
		if(StringUtils.isNotBlank(id)){
			vehAppDevice = vehAppDeviceService.getById(Integer.valueOf(id));
		}
		if(StringUtils.isNoneBlank(note)){
			note = URLDecoder.decode(note,"UTF-8");
			int notes = 0;
			if(note.equals("1")){
				notes = 1;
			}else if(note.equals("2")){
				notes = 2;
			}else if(note.equals("3")){
				notes = 3;
			}
			vehAppDevice.setNote(notes);
		}
		if(StringUtils.isNotBlank(noteDetails)){
			vehAppDevice.setNoteDetails(noteDetails);
		}
		vehAppDeviceService.updateVehAppDevice(vehAppDevice);
		mv.addObject("appKey", appKey);
		return mv;
	}
}
